<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=2">
<meta name="theme-color" content="#222">
<meta name="generator" content="Hexo 4.2.1">
  <link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon-next.png">
  <link rel="icon" type="image/png" sizes="32x32" href="/images/favicon-32x32-next.png">
  <link rel="icon" type="image/png" sizes="16x16" href="/images/favicon-16x16-next.png">
  <link rel="mask-icon" href="/images/logo.svg" color="#222">

<link rel="stylesheet" href="/css/main.css">


<link rel="stylesheet" href="/lib/font-awesome/css/all.min.css">

<script id="hexo-configurations">
    var NexT = window.NexT || {};
    var CONFIG = {"hostname":"lianyouli.gitee.io","root":"/","scheme":"Mist","version":"7.8.0","exturl":false,"sidebar":{"position":"right","display":"post","padding":18,"offset":12,"onmobile":false},"copycode":{"enable":false,"show_result":false,"style":null},"back2top":{"enable":true,"sidebar":false,"scrollpercent":false},"bookmark":{"enable":false,"color":"#222","save":"auto"},"fancybox":false,"mediumzoom":false,"lazyload":false,"pangu":false,"comments":{"style":"tabs","active":null,"storage":true,"lazyload":false,"nav":null},"algolia":{"hits":{"per_page":10},"labels":{"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}},"localsearch":{"enable":false,"trigger":"auto","top_n_per_article":1,"unescape":false,"preload":false},"motion":{"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}},"path":"search.xml"};
  </script>

  <meta name="description" content="lateral view在处理拆分一列多值的情况非常有用，例如array，map等数据拆分。">
<meta property="og:type" content="article">
<meta property="og:title" content="hive - lateral view使用事例">
<meta property="og:url" content="https://lianyouli.gitee.io/IT/it-bigdata-hive-lateralview/index.html">
<meta property="og:site_name" content="联友的Blog">
<meta property="og:description" content="lateral view在处理拆分一列多值的情况非常有用，例如array，map等数据拆分。">
<meta property="og:locale" content="zh_CN">
<meta property="article:published_time" content="2022-02-13T05:18:24.000Z">
<meta property="article:modified_time" content="2022-02-13T06:02:45.586Z">
<meta property="article:author" content="李联友">
<meta property="article:tag" content="bigdata">
<meta property="article:tag" content="hive">
<meta property="article:tag" content="lateral">
<meta property="article:tag" content="lateralview">
<meta name="twitter:card" content="summary">

<link rel="canonical" href="https://lianyouli.gitee.io/IT/it-bigdata-hive-lateralview/">


<script id="page-configurations">
  // https://hexo.io/docs/variables.html
  CONFIG.page = {
    sidebar: "",
    isHome : false,
    isPost : true,
    lang   : 'zh-CN'
  };
</script>

  <title>hive - lateral view使用事例 | 联友的Blog</title>
  


  <script>
    var _hmt = _hmt || [];
    (function() {
      var hm = document.createElement("script");
      hm.src = "https://hm.baidu.com/hm.js?eb9f10e46b1f09801805fc668f13d477";
      var s = document.getElementsByTagName("script")[0];
      s.parentNode.insertBefore(hm, s);
    })();
  </script>




  <noscript>
  <style>
  .use-motion .brand,
  .use-motion .menu-item,
  .sidebar-inner,
  .use-motion .post-block,
  .use-motion .pagination,
  .use-motion .comments,
  .use-motion .post-header,
  .use-motion .post-body,
  .use-motion .collection-header { opacity: initial; }

  .use-motion .site-title,
  .use-motion .site-subtitle {
    opacity: initial;
    top: initial;
  }

  .use-motion .logo-line-before i { left: initial; }
  .use-motion .logo-line-after i { right: initial; }
  </style>
</noscript>

<link rel="alternate" href="/atom.xml" title="联友的Blog" type="application/atom+xml">
</head>

<body itemscope itemtype="http://schema.org/WebPage">
  <div class="container use-motion">
    <div class="headband"></div>

    <header class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-container">
  <div class="site-nav-toggle">
    <div class="toggle" aria-label="切换导航栏">
      <span class="toggle-line toggle-line-first"></span>
      <span class="toggle-line toggle-line-middle"></span>
      <span class="toggle-line toggle-line-last"></span>
    </div>
  </div>

  <div class="site-meta">

    <a href="/" class="brand" rel="start">
      <span class="logo-line-before"><i></i></span>
      <h1 class="site-title">联友的Blog</h1>
      <span class="logo-line-after"><i></i></span>
    </a>
      <p class="site-subtitle" itemprop="description">密涅瓦的猫头鹰在黄昏起飞</p>
  </div>

  <div class="site-nav-right">
    <div class="toggle popup-trigger">
    </div>
  </div>
</div>




<nav class="site-nav">
  <ul id="menu" class="main-menu menu">
        <li class="menu-item menu-item-home">

    <a href="/" rel="section"><i class="fa fa-home fa-fw"></i>首页</a>

  </li>
        <li class="menu-item menu-item-about">

    <a href="/about/" rel="section"><i class="fa fa-user fa-fw"></i>关于</a>

  </li>
        <li class="menu-item menu-item-tags">

    <a href="/tags/" rel="section"><i class="fa fa-tags fa-fw"></i>标签<span class="badge">25</span></a>

  </li>
        <li class="menu-item menu-item-categories">

    <a href="/categories/" rel="section"><i class="fa fa-th fa-fw"></i>分类<span class="badge">8</span></a>

  </li>
        <li class="menu-item menu-item-archives">

    <a href="/archives/" rel="section"><i class="fa fa-archive fa-fw"></i>归档<span class="badge">31</span></a>

  </li>
  </ul>
</nav>




</div>
    </header>

    
  <div class="back-to-top">
    <i class="fa fa-arrow-up"></i>
    <span>0%</span>
  </div>


    <main class="main">
      <div class="main-inner">
        <div class="content-wrap">
          

          <div class="content post posts-expand">
            

    
  
  
  <article itemscope itemtype="http://schema.org/Article" class="post-block" lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="https://lianyouli.gitee.io/IT/it-bigdata-hive-lateralview/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/header.jpg">
      <meta itemprop="name" content="李联友">
      <meta itemprop="description" content="">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="联友的Blog">
    </span>
      <header class="post-header">
        <h1 class="post-title" itemprop="name headline">
          hive - lateral view使用事例
        </h1>

        <div class="post-meta">
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="far fa-calendar"></i>
              </span>
              <span class="post-meta-item-text">发表于</span>
              

              <time title="创建时间：2022-02-13 13:18:24 / 修改时间：14:02:45" itemprop="dateCreated datePublished" datetime="2022-02-13T13:18:24+08:00">2022-02-13</time>
            </span>
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="far fa-folder"></i>
              </span>
              <span class="post-meta-item-text">分类于</span>
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/IT/" itemprop="url" rel="index"><span itemprop="name">IT</span></a>
                </span>
            </span>

          

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">

      
        <blockquote>
<p>lateral view在处理拆分一列多值的情况非常有用，例如array，map等数据拆分。</p>
</blockquote>
<a id="more"></a>

<ol>
<li><p>创建一个专门用户hive language manual的数据</p>
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">create</span> <span class="keyword">database</span> langmanual;</span><br><span class="line"><span class="keyword">use</span> langmanual;</span><br></pre></td></tr></table></figure>
</li>
<li><p>创建一个lateral view专属表： pageads</p>
</li>
</ol>
<ul>
<li><p><a href="https://cwiki.apache.org/confluence/display/Hive/LanguageManual+LateralView" target="_blank" rel="noopener">lateral view</a></p>
</li>
<li><p><a href="https://cwiki.apache.org/confluence/display/Hive/LanguageManual+UDF#LanguageManualUDF-Built-inTable-GeneratingFunctions(UDTF)" target="_blank" rel="noopener">Built-in Table-Generating Functions[UDTF]</a></p>
</li>
<li><p>syntax [改进版本]</p>
<figure class="highlight"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">lateralView: LATERAL VIEW [outer] udtf(expression) tableAlias AS columnAlias (',' columnAlias)*</span><br><span class="line">fromClause: FROM baseTable (',' lateralView)*</span><br></pre></td></tr></table></figure>

<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">drop</span> <span class="keyword">table</span> <span class="keyword">if</span> <span class="keyword">exists</span> pageads;</span><br><span class="line"><span class="keyword">create</span> <span class="keyword">table</span> pageAds</span><br><span class="line">( pageid <span class="keyword">string</span>, </span><br><span class="line">adid_list <span class="built_in">array</span>&lt;<span class="built_in">int</span>&gt;</span><br><span class="line">);</span><br></pre></td></tr></table></figure></li>
</ul>
<ol start="3">
<li><p>插入两条数据</p>
<blockquote>
<p>array关键字</p>
</blockquote>
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">insert</span> <span class="keyword">into</span> pageAds <span class="keyword">values</span> (<span class="string">'front-page'</span>, <span class="built_in">array</span>(<span class="number">1</span>, <span class="number">2</span>, <span class="number">3</span>));</span><br><span class="line"><span class="keyword">insert</span> <span class="keyword">into</span> pageAds <span class="keyword">values</span> (<span class="string">'contact-page'</span>, <span class="built_in">array</span>(<span class="number">3</span>, <span class="number">4</span>, <span class="number">5</span>));</span><br></pre></td></tr></table></figure>
</li>
<li><p>查看数据</p>
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">select</span> * <span class="keyword">from</span> pageads ;</span><br></pre></td></tr></table></figure>

<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line">&#x2F;*</span><br><span class="line">pageid      |adid_list|</span><br><span class="line">------------|---------|</span><br><span class="line">front-page  |[1,2,3]  |</span><br><span class="line">contact-page|[3,4,5]  |</span><br><span class="line">*&#x2F;</span><br></pre></td></tr></table></figure>
</li>
<li><p>使用lateral view 拆分广告id列表</p>
<blockquote>
<p>多个值转换成多行</p>
</blockquote>
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">  <span class="keyword">select</span> pageid, adid </span><br><span class="line"><span class="keyword">from</span> pageads <span class="keyword">lateral</span> <span class="keyword">view</span> <span class="keyword">explode</span>(adid_list) adTable <span class="keyword">as</span> adid;</span><br></pre></td></tr></table></figure>

<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line">&#x2F;*</span><br><span class="line">pageid      |adid|</span><br><span class="line">------------|----|</span><br><span class="line">front-page  |   1|</span><br><span class="line">front-page  |   2|</span><br><span class="line">front-page  |   3|</span><br><span class="line">contact-page|   3|</span><br><span class="line">contact-page|   4|</span><br><span class="line">contact-page|   5|</span><br><span class="line">*&#x2F;</span><br></pre></td></tr></table></figure>
</li>
<li><p>lateral view拆分成多个字段：adidx, adid [index，value]。</p>
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">select</span> pageid, adidx, adid <span class="keyword">from</span> pageads <span class="keyword">lateral</span> <span class="keyword">view</span> posexplode(adid_list) adTable <span class="keyword">as</span> adidx, adid;</span><br></pre></td></tr></table></figure>

<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line">&#x2F;*</span><br><span class="line">pageid      |adidx|adid|</span><br><span class="line">------------|-----|----|</span><br><span class="line">front-page  |    0|   1|</span><br><span class="line">front-page  |    1|   2|</span><br><span class="line">front-page  |    2|   3|</span><br><span class="line">contact-page|    0|   3|</span><br><span class="line">contact-page|    1|   4|</span><br><span class="line">contact-page|    2|   5|</span><br><span class="line"> *&#x2F;</span><br></pre></td></tr></table></figure>
</li>
<li><p>插入adid_list为null的记录</p>
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">insert</span> <span class="keyword">into</span> pageAds(pageid) <span class="keyword">values</span> (<span class="string">'link-page'</span>);</span><br></pre></td></tr></table></figure>
</li>
<li><p>查看记录</p>
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">select</span> * <span class="keyword">from</span> pageads ;</span><br></pre></td></tr></table></figure>

<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">| pageid       | adid_list |</span><br><span class="line">| ------------ | --------- |</span><br><span class="line">| front-page   | [1,2,3]   |</span><br><span class="line">| contact-page | [3,4,5]   |</span><br><span class="line">| link-page    | NULL      |</span><br></pre></td></tr></table></figure>
</li>
<li><p>查看lateral view针对null记录的处理</p>
<blockquote>
<p>将会忽略 adid_list为NULL记录</p>
</blockquote>
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">select</span> pageid, adid </span><br><span class="line"><span class="keyword">from</span> pageads <span class="keyword">lateral</span> <span class="keyword">view</span> <span class="keyword">explode</span>(adid_list) adTable <span class="keyword">as</span> adid;</span><br></pre></td></tr></table></figure>

<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line">&#x2F;* </span><br><span class="line">pageid      |adid|</span><br><span class="line">------------|----|</span><br><span class="line">front-page  |   1|</span><br><span class="line">front-page  |   2|</span><br><span class="line">front-page  |   3|</span><br><span class="line">contact-page|   3| </span><br><span class="line">contact-page|   4|</span><br><span class="line">contact-page|   5|</span><br><span class="line">*&#x2F;</span><br></pre></td></tr></table></figure>
</li>
<li><p>查看lateral view outer 对null记录的处理</p>
<blockquote>
<p>加上outer关键字将会保留id_list为null的记录</p>
</blockquote>
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">select</span> pageid, adid </span><br><span class="line"><span class="keyword">from</span> pageads <span class="keyword">lateral</span> <span class="keyword">view</span> <span class="keyword">outer</span> <span class="keyword">explode</span>(adid_list) adTable <span class="keyword">as</span> adid;</span><br></pre></td></tr></table></figure>

<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line">&#x2F;* </span><br><span class="line">pageid      |adid|</span><br><span class="line">------------|----|</span><br><span class="line">front-page  |   1|</span><br><span class="line">front-page  |   2|</span><br><span class="line">front-page  |   3|</span><br><span class="line">contact-page|   3|</span><br><span class="line">contact-page|   4|</span><br><span class="line">contact-page|   5|</span><br><span class="line">link-page   |    |</span><br><span class="line">*&#x2F;</span><br></pre></td></tr></table></figure>
</li>
<li><p>lateral view 对group by的处理</p>
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">select</span> adid, <span class="keyword">count</span>(adid)</span><br><span class="line"><span class="keyword">from</span> pageads  <span class="keyword">lateral</span> <span class="keyword">view</span> <span class="keyword">explode</span>(adid_list) adTable <span class="keyword">as</span> adid</span><br><span class="line"><span class="keyword">group</span> <span class="keyword">by</span> adid;</span><br></pre></td></tr></table></figure>

<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line">&#x2F;*</span><br><span class="line">adid|_c1|</span><br><span class="line">----|---|</span><br><span class="line"> 1|  1|</span><br><span class="line"> 2|  1|</span><br><span class="line"> 3|  2|</span><br><span class="line"> 4|  1|</span><br><span class="line"> 5|  1| </span><br><span class="line">*&#x2F;</span><br></pre></td></tr></table></figure>
</li>
<li><p>多个多值字段： 新增一个array字段，visit_count</p>
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">alter</span> <span class="keyword">table</span> pageads  <span class="keyword">add</span> <span class="keyword">columns</span> (visit_count <span class="built_in">array</span>&lt;<span class="built_in">int</span>&gt; <span class="keyword">comment</span> <span class="string">'访问次数'</span>);</span><br></pre></td></tr></table></figure>
</li>
<li><p>造数&amp;查看数据</p>
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">insert</span> <span class="keyword">into</span> pageAds <span class="keyword">values</span> (<span class="string">'footer-page'</span>, <span class="built_in">array</span>(<span class="number">7</span>, <span class="number">8</span>, <span class="number">9</span>), <span class="built_in">array</span>(<span class="number">700</span>, <span class="number">800</span>, <span class="number">900</span>));</span><br><span class="line"><span class="keyword">select</span> * <span class="keyword">from</span> pageads ;</span><br></pre></td></tr></table></figure>

<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line">&#x2F;*</span><br><span class="line">pageid      |adid_list|visit_count  |</span><br><span class="line">------------|---------|-------------|</span><br><span class="line">front-page  |[1,2,3]  |NULL         |</span><br><span class="line">contact-page|[3,4,5]  |NULL         |</span><br><span class="line">link-page   |NULL     |NULL         |</span><br><span class="line">footer-page |[7,8,9]  |[700,800,900]|</span><br><span class="line">*&#x2F;</span><br></pre></td></tr></table></figure>
</li>
<li><p>一个lateral view对另外一个字段的处理</p>
<blockquote>
<p>另外一字段和常规字段一样，都是不变。</p>
</blockquote>
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">select</span> * </span><br><span class="line"><span class="keyword">from</span> pageads </span><br><span class="line"><span class="keyword">lateral</span> <span class="keyword">view</span> <span class="keyword">explode</span>(adid_list) adTable <span class="keyword">as</span> adid;</span><br></pre></td></tr></table></figure>

<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br></pre></td><td class="code"><pre><span class="line">&#x2F;*</span><br><span class="line">pageid      |adid_list|visit_count  |adid|</span><br><span class="line">------------|---------|-------------|----|</span><br><span class="line">front-page  |[1,2,3]  |NULL         |   1|</span><br><span class="line">front-page  |[1,2,3]  |NULL         |   2|</span><br><span class="line">front-page  |[1,2,3]  |NULL         |   3|</span><br><span class="line">contact-page|[3,4,5]  |NULL         |   3|</span><br><span class="line">contact-page|[3,4,5]  |NULL         |   4|</span><br><span class="line">contact-page|[3,4,5]  |NULL         |   5|</span><br><span class="line">footer-page |[7,8,9]  |[700,800,900]|   7|</span><br><span class="line">footer-page |[7,8,9]  |[700,800,900]|   8|</span><br><span class="line">footer-page |[7,8,9]  |[700,800,900]|   9|</span><br><span class="line">*&#x2F;</span><br></pre></td></tr></table></figure>
</li>
<li><p>多个lateral view</p>
<blockquote>
<p>会拆分成多对多情况，即full outer join中，排除lateral view 任何字段为null的记录。</p>
</blockquote>
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">select</span> * </span><br><span class="line"><span class="keyword">from</span> pageads </span><br><span class="line"><span class="keyword">lateral</span> <span class="keyword">view</span> <span class="keyword">explode</span>(adid_list) adTable <span class="keyword">as</span> adid</span><br><span class="line"><span class="keyword">lateral</span> <span class="keyword">view</span> <span class="keyword">explode</span>(visit_count)  vTable <span class="keyword">as</span> vct;</span><br></pre></td></tr></table></figure>

<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br></pre></td><td class="code"><pre><span class="line">&#x2F;*</span><br><span class="line">pageid     |adid_list|visit_count  |adid|vct|</span><br><span class="line">-----------|---------|-------------|----|---|</span><br><span class="line">footer-page|[7,8,9]  |[700,800,900]|   7|700|</span><br><span class="line">footer-page|[7,8,9]  |[700,800,900]|   7|800|</span><br><span class="line">footer-page|[7,8,9]  |[700,800,900]|   7|900|</span><br><span class="line">footer-page|[7,8,9]  |[700,800,900]|   8|700|</span><br><span class="line">footer-page|[7,8,9]  |[700,800,900]|   8|800|</span><br><span class="line">footer-page|[7,8,9]  |[700,800,900]|   8|900|</span><br><span class="line">footer-page|[7,8,9]  |[700,800,900]|   9|700|</span><br><span class="line">footer-page|[7,8,9]  |[700,800,900]|   9|800|</span><br><span class="line">footer-page|[7,8,9]  |[700,800,900]|   9|900|</span><br><span class="line">*&#x2F;</span><br></pre></td></tr></table></figure>
</li>
<li><p>多个lateral view outer</p>
<blockquote>
<p>会拆分成多对多情况，类似full outer join。</p>
</blockquote>
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">select</span> * </span><br><span class="line"><span class="keyword">from</span> pageads </span><br><span class="line"><span class="keyword">lateral</span> <span class="keyword">view</span> <span class="keyword">outer</span> <span class="keyword">explode</span>(adid_list) adTable <span class="keyword">as</span> adid</span><br><span class="line"><span class="keyword">lateral</span> <span class="keyword">view</span> <span class="keyword">outer</span> <span class="keyword">explode</span>(visit_count)  vTable <span class="keyword">as</span> vct;</span><br></pre></td></tr></table></figure>

<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br></pre></td><td class="code"><pre><span class="line">&#x2F;*</span><br><span class="line">pageid      |adid_list|visit_count  |adid|vct|</span><br><span class="line">------------|---------|-------------|----|---|</span><br><span class="line">front-page  |[1,2,3]  |NULL         |   1|   |</span><br><span class="line">front-page  |[1,2,3]  |NULL         |   2|   |</span><br><span class="line">front-page  |[1,2,3]  |NULL         |   3|   |</span><br><span class="line">contact-page|[3,4,5]  |NULL         |   3|   |</span><br><span class="line">contact-page|[3,4,5]  |NULL         |   4|   |</span><br><span class="line">contact-page|[3,4,5]  |NULL         |   5|   |</span><br><span class="line">footer-page |[7,8,9]  |[700,800,900]|   7|700|</span><br><span class="line">footer-page |[7,8,9]  |[700,800,900]|   7|800|</span><br><span class="line">footer-page |[7,8,9]  |[700,800,900]|   7|900|</span><br><span class="line">footer-page |[7,8,9]  |[700,800,900]|   8|700|</span><br><span class="line">footer-page |[7,8,9]  |[700,800,900]|   8|800|</span><br><span class="line">footer-page |[7,8,9]  |[700,800,900]|   8|900|</span><br><span class="line">footer-page |[7,8,9]  |[700,800,900]|   9|700|</span><br><span class="line">footer-page |[7,8,9]  |[700,800,900]|   9|800|</span><br><span class="line">footer-page |[7,8,9]  |[700,800,900]|   9|900|</span><br><span class="line"> *&#x2F;</span><br></pre></td></tr></table></figure>
</li>
</ol>

    </div>

    
    
    
        

  <div class="followme">
    <p>欢迎关注我的其它发布渠道</p>

    <div class="social-list">

        <div class="social-item">
          <a target="_blank" class="social-link" href="/atom.xml">
            <span class="icon">
              <i class="fa fa-rss"></i>
            </span>

            <span class="label">RSS</span>
          </a>
        </div>
    </div>
  </div>


      <footer class="post-footer">
          <div class="post-tags">
              <a href="/tags/bigdata/" rel="tag"># bigdata</a>
              <a href="/tags/hive/" rel="tag"># hive</a>
              <a href="/tags/lateral/" rel="tag"># lateral</a>
              <a href="/tags/lateralview/" rel="tag"># lateralview</a>
          </div>

        


        
    <div class="post-nav">
      <div class="post-nav-item">
    <a href="/Payment/%E6%B3%95%E8%A7%84/rules-pboc-no259/" rel="prev" title="259号文">
      <i class="fa fa-chevron-left"></i> 259号文
    </a></div>
      <div class="post-nav-item">
    <a href="/IT/it-bigdata-dataflow-nifi-cluster-installation/" rel="next" title="Nifi集群安装">
      Nifi集群安装 <i class="fa fa-chevron-right"></i>
    </a></div>
    </div>
      </footer>
    
  </article>
  
  
  



          </div>
          

<script>
  window.addEventListener('tabs:register', () => {
    let { activeClass } = CONFIG.comments;
    if (CONFIG.comments.storage) {
      activeClass = localStorage.getItem('comments_active') || activeClass;
    }
    if (activeClass) {
      let activeTab = document.querySelector(`a[href="#comment-${activeClass}"]`);
      if (activeTab) {
        activeTab.click();
      }
    }
  });
  if (CONFIG.comments.storage) {
    window.addEventListener('tabs:click', event => {
      if (!event.target.matches('.tabs-comment .tab-content .tab-pane')) return;
      let commentClass = event.target.classList[1];
      localStorage.setItem('comments_active', commentClass);
    });
  }
</script>

        </div>
          
  
  <div class="toggle sidebar-toggle">
    <span class="toggle-line toggle-line-first"></span>
    <span class="toggle-line toggle-line-middle"></span>
    <span class="toggle-line toggle-line-last"></span>
  </div>

  <aside class="sidebar">
    <div class="sidebar-inner">

      <ul class="sidebar-nav motion-element">
        <li class="sidebar-nav-toc">
          文章目录
        </li>
        <li class="sidebar-nav-overview">
          站点概览
        </li>
      </ul>

      <!--noindex-->
      <div class="post-toc-wrap sidebar-panel">
      </div>
      <!--/noindex-->

      <div class="site-overview-wrap sidebar-panel">
        <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
    <img class="site-author-image" itemprop="image" alt="李联友"
      src="/images/header.jpg">
  <p class="site-author-name" itemprop="name">李联友</p>
  <div class="site-description" itemprop="description"></div>
</div>
<div class="site-state-wrap motion-element">
  <nav class="site-state">
      <div class="site-state-item site-state-posts">
          <a href="/archives/">
        
          <span class="site-state-item-count">31</span>
          <span class="site-state-item-name">日志</span>
        </a>
      </div>
      <div class="site-state-item site-state-categories">
            <a href="/categories/">
          
        <span class="site-state-item-count">8</span>
        <span class="site-state-item-name">分类</span></a>
      </div>
      <div class="site-state-item site-state-tags">
            <a href="/tags/">
          
        <span class="site-state-item-count">25</span>
        <span class="site-state-item-name">标签</span></a>
      </div>
  </nav>
</div>
  <div class="links-of-author motion-element">
      <span class="links-of-author-item">
        <a href="https://github.com/lianyouli" title="GitHub → https:&#x2F;&#x2F;github.com&#x2F;lianyouli" rel="noopener" target="_blank"><i class="fab fa-github fa-fw"></i>GitHub</a>
      </span>
  </div>



      </div>

    </div>
  </aside>
  <div id="sidebar-dimmer"></div>


      </div>
    </main>

    <footer class="footer">
      <div class="footer-inner">
        

        

<div class="copyright">
  
  &copy; 
  <span itemprop="copyrightYear">2023</span>
  <span class="with-love">
    <i class="fa fa-heart"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">李联友</span>
</div>
  <div class="powered-by">由 <a href="https://hexo.io/" class="theme-link" rel="noopener" target="_blank">Hexo</a> & <a href="https://mist.theme-next.org/" class="theme-link" rel="noopener" target="_blank">NexT.Mist</a> 强力驱动
  </div>

<script src="/js/jquery.min.js"> </script>

        








      </div>
    </footer>
  </div>

  
  <script src="/lib/anime.min.js"></script>
  <script src="/lib/velocity/velocity.min.js"></script>
  <script src="/lib/velocity/velocity.ui.min.js"></script>

<script src="/js/utils.js"></script>

<script src="/js/motion.js"></script>


<script src="/js/schemes/muse.js"></script>


<script src="/js/next-boot.js"></script>



<script src="/js/code-unfold.js"></script>


  















  

  

</body>
</html>
